package qcmPlus.tools;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Crypter {

	public static String cryptage(String password) {
		MessageDigest mdAlgorithm;
		byte[] digest;
		StringBuffer hexString = new StringBuffer();

		try {
			mdAlgorithm = MessageDigest.getInstance("MD5");
			mdAlgorithm.update(password.getBytes());
			digest = mdAlgorithm.digest();
			for (int i = 0; i < digest.length; i++) {
				password = Integer.toHexString(0xFF & digest[i]);

				if (password.length() < 2) {
					password = "0" + password;
				}

				hexString.append(password);
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return hexString.toString();

	}

}
